package LintCode;

import org.junit.Assert;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class TriangleCount {


    @Test
    public void testTiangleCount() {
        Integer[][] integers = triangleCount();

        Integer[][] arr = {{3,4,6}, {3,6,7},{4,6,7}};
        Assert.assertEquals(integers, arr);

    }

    public Integer[][] triangleCount() {

        Integer[] array = {3, 4, 6, 7};
//        Integer[] array = {4, 4, 4, 4};

        Integer[][] array2 = new Integer[10][3];

        int n = 0;

        for (int i = 0; i < array.length - 2; i++) {
            for (int j = i + 1; j < array.length - 1; j++) {
                Integer k = j;
                while (k < array.length - 1) {
                    Integer num1 = array[i];
                    Integer num2 = array[j];
                    Integer num3 = array[k + 1];

                    if ((num1 + num2 > num3) && (Math.abs(num1 - num2) < num3)) {
                        array2[n][0] = num1;
                        array2[n][1] = num2;
                        array2[n][2] = num3;
                        ++n;
                    }
                    ++k;
                }
            }
        }

        Integer[][] result = new Integer[n][2];
        for (int i = 0; i < n; i++) {
            result[i] = array2[i].clone();
        }
        return result;


    }

}
